package com.merry.spring5.resource;

import java.io.IOException;
import java.io.InputStream;

import org.springframework.core.io.ClassPathResource;

/**
 * @author ybzou
 * 访问类路径下资源
 */
public class ClassPathResourceDemo {

    public static void main(String[] args) throws Exception {
        loadClassPathResource("bean.xml");
    }

    public static void loadClassPathResource(String path) throws Exception {
        ClassPathResource classPathResource=new ClassPathResource(path);
        System.out.println(classPathResource.getFilename());
        System.out.println(classPathResource.getURI());
        System.out.println(classPathResource.getInputStream().read());
        InputStream inputStream = classPathResource.getInputStream();
        byte[] bytes=new byte[1024];
        while (inputStream.read(bytes)!=-1){
            System.out.println(new String(bytes));
        }
    }
}
